/** for BorderLayout */
import java.awt.BorderLayout;

/** for Color */
import java.awt.Color;

/** for Dimension */
import java.awt.Dimension;

/** for Font */
import java.awt.Font;

/** for Graphics */
import java.awt.Graphics;

/** for JPanel */
import javax.swing.JPanel;

/**
 * HW 12b & 13b, "RightPanel"<br><br>
 * 
 * This class is for the panel on the right part of the window, 
 * where the next piece, the current score, and the current level is drawn on. 
 * 
 * @author Hyun Seo Chung
 * @version 1.0 04/21/12
 */
public class RightPanel extends JPanel {
	
	/**
	 * serialVersionUID for the RightPanel class
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * middle panel
	 */
	private PlayingPanel m_panel;
//	private Dimension tileDimension;
	
	/**
	 * This is a constructor where it sets up the panel's layout and the preferred size. 
	 */
	public RightPanel() {
		super.setLayout(new BorderLayout());
		super.setPreferredSize(
				new Dimension(Numbers.TWO_HUNDRED.getNumber(), 
						Numbers.SEVEN_HUNDRED.getNumber() 
						+ Numbers.TWENTY_SEVEN.getNumber()));
	}
	
	/**
	 * This is a method that paints the graphics on the panel
	 * 
	 * @param g The Graphics object to be drawn on
	 */
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.WHITE);
		g.setFont(new Font("Futura", Font.BOLD, Numbers.TWENTY.getNumber()));
		g.drawString("Next Piece", Numbers.FIFTY.getNumber(), Numbers.THIRTY.getNumber());
		g.drawRect(Numbers.FIFTY.getNumber(), 
				Numbers.FIFTY.getNumber(), 
				Numbers.HUNDRED_TWENTY.getNumber(), 
				Numbers.HUNDRED.getNumber());
		g.setFont(new Font("OCR A Std", Font.BOLD, Numbers.TWENTY.getNumber()));
		g.drawString(String.format("%" + ("" + (Numbers.FIVE.getNumber() -
				(("" + PlayingPanel.getField().getLevel()).length()
						> Numbers.FOUR.getNumber() 
						? Numbers.FOUR.getNumber() 
						: ("" + PlayingPanel.getField().getLevel()).length())))
						+ "s", "") + "Level: " + 
						PlayingPanel.getField().getLevel(), 
						Numbers.TEN.getNumber(), Numbers.SIX_HUNDRED_SEVETY.getNumber());
		g.drawString(String.format("%" + ("" + (Numbers.FIVE.getNumber() -
				(("" + PlayingPanel.getField().getScore()).length()
						> Numbers.FOUR.getNumber() 
						? Numbers.FOUR.getNumber() 
								: ("" + PlayingPanel.getField().getScore()).length())))
						+ "s", "") + "Score: " + 
						PlayingPanel.getField().getScore(), 
						Numbers.TEN.getNumber(), 
						Numbers.SEVEN_HUNDRED.getNumber() 
						+ Numbers.TWENTY.getNumber());
		
//		tileDimension = m_panel.getTileDimension();
		
		if (m_panel.getNextPiece() != null) {
			for ( int i = 0; i < m_panel.getNextPiece().getModel().length; i++ ) {
				for ( int j = 0; j < m_panel.getNextPiece().getModel().length; j++ ) {
					if (m_panel.getNextPiece().getModel()[i][j] == 1) {
						g.setColor(m_panel.getNextPiece().getColor());
						g.fillRect(Numbers.SIXTY.getNumber() 
								+ j * Numbers.TWENTY_FIVE.getNumber(), 
								Numbers.SEVENTY.getNumber() 
								+ i * Numbers.TWENTY_FIVE.getNumber(), 
								Numbers.TWENTY_FIVE.getNumber(), 
								Numbers.TWENTY_FIVE.getNumber());
					}
				}
			}
		}
		
	}
	
	/**
	 * This is a setter to get the reference of the
	 *  main panel responsible of the main tetris board. 
	 * 
	 * @param p The reference of the current
	 *  PlayingPanel (main tetris board panel) to be used
	 */
	public void setPlayingPanel(PlayingPanel p) {
		m_panel = p;
	}

}
